﻿using AutoMapper;
using MediatR;
using UserLicense.Applicationes.Command;
using UserModels.DTO;
using UserRepositorys.Intface;

namespace UserLicense.Applicationes.CommandHandler
{
    public class TiesAddCommandHandler : IRequestHandler<TiesAddCommand, int>
    {
        private readonly ITiesRepository _tiesRepository;
        private readonly IMapper _mapper;
        public TiesAddCommandHandler(ITiesRepository tiesRepository,IMapper mapper)
        {
            _tiesRepository = tiesRepository;
            _mapper = mapper;
        }

        /// <summary>
        /// 添加关系
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<int> Handle(TiesAddCommand request, CancellationToken cancellationToken)
        {
            RoleMenuInfoDTO model=_mapper.Map<RoleMenuInfoDTO>(request);
            return await _tiesRepository.AddRoleMune(model);
        }
    }
}
